#include<iostream>
#include"Insertion.h"
using namespace std;


void Insertion::sort(int* arr, int len) {
	for (int i = 1; i < len; i++)
	{
		for (int j = i-1; j >=0 ; j--)
		{
			if (greater(arr[j], arr[j + 1])) {
				exch(arr, j, j + 1);
			}
			else
			{
				break;
			}

		}
	}
}


bool Insertion::greater(int v, int w) {
	if (v > w) {
		return true;
	}
	return false;
}

void Insertion::exch(int* arr, int i, int j) {
	int temp = arr[i];
	arr[i] = arr[j];
	arr[j] = temp;
}


void main05() {
	int arr[] = { 9,7,6,5,4,3,2,1 };
	int len = sizeof(arr) / sizeof(arr[0]);
	Insertion insert;
	insert.sort(arr, len);
	for (int i = 0; i < len; i++)
	{
		cout << arr[i] << endl;
	}
}